﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Common.XmlConfig
{
    public class ConfigSetting : BaseConfig
    {
        /// <summary>
        /// 创建分组
        /// </summary>
        /// <param name="key">主键</param>
        /// <param name="Text">文本</param>
        /// <param name="Value">值</param>
        /// <param name="Type">类型</param>
        public ConfigSetting(string key, string Text, string Value, string Type,string Tip=null)
        {
            this._Key = key;
            this.Text = Text;
            this.Value = Value;
            this.Type = (SettingType)Enum.Parse(typeof(SettingType), Type,true);
            this._Node = null;
            this.Tip = Tip;
        }

        /// <summary>
        /// xml节点
        /// </summary>
        /// <param name="node"></param>
        public ConfigSetting(XmlNode node)
        {
            if (node.Attributes["Key"] == null) throw new Exception("属性Key值为空，");
            this._Key = node.Attributes["Key"].Value;
            this.Text = node.Attributes["Text"] == null ? null : node.Attributes["Text"].Value;
            this.Value = node.Attributes["Value"] == null ? null : node.Attributes["Value"].Value;
            this.Type = (SettingType)Enum.Parse(typeof(SettingType), node.Attributes["Type"]==null?"Default":node.Attributes["Type"].Value, true);
            this.Tip = node.Attributes["Tip"] == null ? null : node.Attributes["Tip"].Value;
            this._Node = node;
        }
        private ConfigSetting() { }

        /// <summary>
        /// 值
        /// </summary>
        public string Value { get; set; }

        /// <summary>
        /// 配置类型
        /// </summary>
        public SettingType Type { get; set; }

        /// <summary>
        /// 帮助信息
        /// </summary>
        public string Tip { get; set; }

        /// <summary>
        /// 显示
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return "Key:" + this.Key + ",Text:" + this.Text + ",Value:" + this.Value;
        }
    }
}
